<template>
<!-- 	<view>
		<uv-drop-down ref="dropDown" sign="dropDown_1" text-active-color="#3c9cff"
			:extra-icon="{name:'arrow-down-fill',color:'#666',size:'26rpx'}"
			:extra-active-icon="{name:'arrow-up-fill',color:'#3c9cff',size:'26rpx'}" :defaultValue="defaultValue"
			:custom-style="{padding: '0 30rpx'}" @click="selectMenu">
			<uv-drop-down-item name="order" type="2" :label="dropItem('order').label" :value="dropItem('order').value">
			</uv-drop-down-item>

		</uv-drop-down>
		<uv-drop-down-popup sign="dropDown_1" :click-overlay-on-close="true" :currentDropItem="currentDropItem"
			@clickItem="clickItem" @popupChange="change"></uv-drop-down-popup>
	</view> -->

	<view class="" style="height:100%;overflow: hidden;">
		<uv-cell-group>
			<uv-cell v-for="(item, index) in list" :key="index" :title="item.name" :value="item.create_at"
				required="true" @click="goDetail2(item.id)">
			</uv-cell>
		</uv-cell-group>
	</view>

</template>
<script>
	import config from "@/config/config.js";
	import xcUniappUtils from '@/library/xcore/js/XcUniappUtils.js';
	import xcHttpUtils from '@/library/xcore/js/XcHttpUtils.js';
	import xcViewUtils from '@/library/xcore/js/XcViewUtils.js';
	import xcCloginUtils from '@/library/xcore/js/XcCloginUtils.js';
	import xcCWeixinMpLoginUtils from '@/library/xcore/js/XcCWeixinMpLoginUtils.js';
	import {
		xsStringUtils,
		xsDateUtils,
		xsArrayUtils
	} from 'xstack-for-javascript';

	export default {
		onPageScroll() {
			// 滚动后及时更新位置
			this.$refs.dropDown.init();
		},
		computed: {
			dropItem(name) {
				return (name) => {
					const result = {};
					const find = this.result.find(item => item.name === name);
					if (find) {
						result.label = find.label;
						result.value = find.value;
					} else {
						result.label = this[name].label;
						result.value = this[name].value;
					}
					return result;
				}
			},
			// 获取当前下拉筛选项
			currentDropItem() {
				return this[this.activeName];
			}
		},
		data() {
			return {
				
				// 表示value等于这些值，就属于默认值
				defaultValue: [0, 'all', '0'],
				// 筛选结果
				result: [{
					name: 'order',
					label: '所属省份',
					value: '1'
				}],

				activeName: 'order',
				order: {
					label: '查看全部',
					value: '1',
					activeIndex: 0,
					color: '#333',
					activeColor: '#2878ff',
					child: []
				},
				shengfen_id:'',
				list: [],
				config: config,
				xsStringUtils: xsStringUtils,
				xsDateUtils: xsDateUtils,
				sp: {
					id: null
				},
				sr: {
					row: [],
					userinfo: null
				},
				control: {}
			}
		},
		onLoad(options) {
			let that = this;
			that.xinit();

		},
		onShow() {
			let that = this;
			this.getdata()

			this.getshengfen()
		},

		onPullDownRefresh() {
			let that = this;
			setTimeout(function() {
				that.public_show();
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			change(e) {
				// console.log('弹窗打开状态：', e);
			},

			selectMenu(e) {
				const {
					name,
					active,
					type
				} = e;
				this.activeName = name;
				// type 等于1 的需要特殊处理：type不等于1可以忽略
				if (type == 1) {
					this.clickItem({
						name: 'vip_type',
						label: 'VIP文档',
						value: e.active ? 1 : 0
					});
				} else {
					const find = this.result.find(item => item.name == this.activeName);
					if (find) {
						const findIndex = this[this.activeName].child.findIndex(item => item.label == find.label && item
							.value == find.value);
						this[this.activeName].activeIndex = findIndex;
					} else {
						this[this.activeName].activeIndex = 0;
					}
				}
			},

			clickItem(e) {
				// 下面有重新赋值，所以用let
				let {
					label,
					value
				} = e;
				const findIndex = this.result.findIndex(item => item.name == this.activeName);
				if (this.defaultValue.indexOf(value) > -1 && this[this.activeName].label) {
					label = this[this.activeName].label;
				}
				// 已经存在筛选项
				if (findIndex > -1) {
					this.$set(this.result, findIndex, {
						name: this.activeName,
						label,
						value
					})
				} else {
					this.result.push({
						name: this.activeName,
						label,
						value
					});
				}
				this.result = this.result.filter(item => this.defaultValue.indexOf(item.value) == -1);

				// uni.showModal({
				// 	content: `筛选的值：${JSON.stringify(this.result)}`
				// })
				var that = this
				this.shengfen_id = this.result[0].value
				this.getdata()
			},

			getdata() {
				var that = this
				uni.request({
					url: 'https://shanghaihuxi.cn/api/index/getfenbao',
					header: {
						'Content-Type': 'application/json' // 请求头，可以根据接口要求修改
					},
					success: (res) => {
						console.log(222, res)
						that.list = res.data.data
					}
				});
			},

			getshengfen() {
				var that = this
				uni.request({
					url: 'https://shanghaihuxi.cn/api/index/getshengfen',
					header: {
						'Content-Type': 'application/json' // 请求头，可以根据接口要求修改
					},
					success: (res) => {
						console.log(44444, res)
						// that.order.child = [{
						// 		label: '查看全部',
						// 		value: '1'
						// 		}]
						that.order.child = res.data.data
					}
				});
			},
			goDetail2(id) {
				uni.navigateTo({
					url: '/pages/xcdemo/baobiao_renyuanliebiao?gongsi_id=' + id
				});
			},
			control_clickLogin() {

				uni.navigateTo({
					url: '/pages/xclogin/me'
				});
			},
			goDetail(id) {
				console.log(id)
				uni.navigateTo({
					url: '/pages/csmwj/paper?id=' + id
				});
			},
			xinit() {
				let that = this;

			},
			public_show() {
				let that = this;
			},
			public_reset() {
				let that = this;
				that.public_show();
			},
			control_switchLocale(locale) {
				let that = this;
				xcLangUtils.switchLocale(locale);
			}
		}
	}
</script>

<style lang="scss">

</style>